package com.atguigu.yygh.common.result;

import lombok.Data;
import lombok.experimental.Accessors;

import java.util.HashMap;
import java.util.Map;

@Data
@Accessors(chain = true)  //实现链式链式编程，如：result.setCode("200").setMessage("成功")
public class Result {
    private Boolean success;//是否成功
    private Integer code;//返回码
    private String message;//返回消息
    private Map<String, Object> data = new HashMap<>();//返回数据

    public Result() {
    }

    public static Result ok() {
        return new Result()
                .setSuccess(true)
                .setCode(ResultCode.SUCCESS)
                .setMessage("成功");
    }

    public static Result fail() {
        return new Result()
                .setSuccess(false)
                .setCode(ResultCode.ERROR)
                .setMessage("失败");
    }

    public Result setData(String s, Object o) {
        data.put(s, o);
        return this;
    }
}
